//
//  MBGoodsDetailTitleView.m
//  MemberBusiness-ios
//
//  Created by cherry pu on 2018/5/4.
//  Copyright © 2018年 zhangXin. All rights reserved.
//

#import "MBGoodsDetailTitleView.h"

@interface MBGoodsDetailTitleView()
@property (nonatomic,weak) UILabel* titleLabel;
@property (nonatomic,weak) UILabel* detailLabel;
@property (nonatomic,weak) UILabel* moneyLabel;
@property (nonatomic,weak) UILabel* oldMoneyLabel;
@property (nonatomic,weak) UILabel* saleNumLabel;
@property (nonatomic,weak)UILabel* starTitleLabel;

@end

@implementation MBGoodsDetailTitleView

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        
        UILabel* titleLabel = [[UILabel alloc]init];
        self.titleLabel = titleLabel;
        titleLabel.text = @"Apple/苹果iPhone X 全网通4G智能手机苹果X10";
        titleLabel.font = [UIFont lf_systemFontOfSize:14];
        titleLabel.textColor = [UIColor colorWithR:40 G:40 B:40];
        titleLabel.numberOfLines = 0;
        [self addSubview:titleLabel];
        
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).with.offset([UIView lf_sizeFromIphone6:16]);
            make.left.equalTo(self).with.offset([UIView lf_sizeFromIphone6:12]);
            make.right.equalTo(self).with.offset([UIView lf_sizeFromIphone6:-16]);
        }];
        
        UILabel* detailLabel = [[UILabel alloc]init];
        self.detailLabel = detailLabel;
        detailLabel.numberOfLines = 0;
        detailLabel.text = @"品质认证/性价比品质款/一年无忧质保";
        detailLabel.font = [UIFont lf_systemFontOfSize:12];
        detailLabel.textColor = COLOR_MAIN;
        [self addSubview:detailLabel];
        
        [detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(titleLabel.mas_bottom).with.offset([UIView lf_sizeFromIphone6:10]);
            make.left.equalTo(self).with.offset([UIView lf_sizeFromIphone6:12]);
            make.right.equalTo(self).with.offset([UIView lf_sizeFromIphone6:-12]);
        }];
        
        UILabel* moneyLabel = [[UILabel alloc]init];
        self.moneyLabel = moneyLabel;
        moneyLabel.text = @"¥7511.00";
        moneyLabel.font = [UIFont lf_systemFontOfSize:15];
        moneyLabel.textColor = [UIColor colorWithR:255 G:0 B:0];
        [self addSubview:moneyLabel];
        
        [moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset([UIView lf_sizeFromIphone6:12]);
            make.top.equalTo(detailLabel.mas_bottom).with.offset([UIView lf_sizeFromIphone6:12]);
        }];
        
        UIView* line = [[UIView alloc]init];
        line.backgroundColor = COLOR_LINE;
        [self addSubview:line];
        
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(moneyLabel.mas_bottom).with.offset([UIView lf_sizeFromIphone6:15]);
            make.left.equalTo(self).with.offset([UIView lf_sizeFromIphone6:12]);
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH-[UIView lf_sizeFromIphone6:24], [UIView lf_sizeFromIphone6:1]));
        }];
        
        UILabel* saleNumLabel = [[UILabel alloc]init];
        self.saleNumLabel = saleNumLabel;
        [self addSubview:saleNumLabel];
        
        [saleNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(moneyLabel);
            make.top.equalTo(line.mas_bottom).with.offset([UIView lf_sizeFromIphone6:15]);
        }];
        
        UILabel* starTitleLabel = [[UILabel alloc]init];
        self.starTitleLabel = starTitleLabel;
        [self addSubview:starTitleLabel];
        
        [starTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(saleNumLabel.mas_bottom).with.offset([UIView lf_sizeFromIphone6:12]);
            make.left.equalTo(saleNumLabel);
            make.bottom.equalTo(self).with.offset([UIView lf_sizeFromIphone6:-15]);
        }];
        
        
    }
    return self;
}

-(void)setGoodsDetailModel:(MBGoodsInfoModel *)goodsDetailModel
{
    _goodsDetailModel = goodsDetailModel;
    
    self.titleLabel.text = goodsDetailModel.goods.goods_name;
    self.detailLabel.text = goodsDetailModel.goods.goods_remark;
    if (goodsDetailModel.goods.exchange_integral > 0) {
        NSString* str = [NSString stringWithFormat:@"￥%@ +%ld积分",goodsDetailModel.goods.shop_price,(long)goodsDetailModel.goods.exchange_integral];
        NSMutableAttributedString* attStr = [[NSMutableAttributedString alloc]initWithString:str attributes:@{NSFontAttributeName:[UIFont lf_systemFontOfSize:15],NSForegroundColorAttributeName:[UIColor redColor]}];
        self.moneyLabel.attributedText = attStr;
    }else {
        self.moneyLabel.text = [NSString stringWithFormat:@"￥%@",goodsDetailModel.goods.shop_price];
    }
    NSString* star = [NSString stringWithFormat:@"服务  %@",goodsDetailModel.goods.service_provider];
    NSMutableAttributedString* starAtt = [[NSMutableAttributedString alloc]initWithString:star attributes:@{NSFontAttributeName:[UIFont lf_systemFontOfSize:12],NSForegroundColorAttributeName:[UIColor colorWithR:51 G:51 B:51]}];
    [starAtt addAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithR:153 G:153 B:153]} range:NSMakeRange(0, 2)];
    self.starTitleLabel.attributedText = starAtt;
    
    if (goodsDetailModel.goods.is_free_shipping == 1) {
        NSString* sale = @"运费  包邮";
        NSMutableAttributedString* saleAtt = [[NSMutableAttributedString alloc]initWithString:sale attributes:@{NSFontAttributeName:[UIFont lf_systemFontOfSize:12],NSForegroundColorAttributeName:[UIColor colorWithR:51 G:51 B:51]}];
        [saleAtt addAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithR:153 G:153 B:153]} range:NSMakeRange(0, 2)];
        self.saleNumLabel.attributedText = saleAtt;
    }else {
        NSString* sale = @"运费  不包邮";
        NSMutableAttributedString* saleAtt = [[NSMutableAttributedString alloc]initWithString:sale attributes:@{NSFontAttributeName:[UIFont lf_systemFontOfSize:12],NSForegroundColorAttributeName:[UIColor colorWithR:51 G:51 B:51]}];
        [saleAtt addAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithR:153 G:153 B:153]} range:NSMakeRange(0, 2)];
        self.saleNumLabel.attributedText = saleAtt;
    }
    
}

@end
